package com.gitee.wsl.compose.ui.richtext.edit.model.span.style

import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextRange
import com.gitee.wsl.compose.ui.richtext.edit.annotation.ExperimentalRichTextApi
import com.gitee.wsl.compose.ui.richtext.edit.model.RichTextConfig
import com.gitee.wsl.compose.ui.richtext.edit.state.RichTextState


@ExperimentalRichTextApi
interface RichSpanStyle {
    val spanStyle: (RichTextConfig) -> SpanStyle
        get() = { DefaultSpanStyle }

    /**
     * If true, the user can add new text in the edges of the span,
     * For example, if the span is "Hello" and the user adds "World" in the end, the span will be "Hello World"
     * If false, the user can't add new text in the edges of the span,
     * For example, if the span is a "Hello" link and the user adds "World" in the end, the "World" will be added in a separate a span,
     */
    val acceptNewTextInTheEdges: Boolean
        get() = false

    fun DrawScope.drawCustomStyle(
        layoutResult: TextLayoutResult,
        textRange: TextRange,
        richTextConfig: RichTextConfig,
        topPadding: Float = 0f,
        startPadding: Float = 0f,
    ) = Unit

    fun AnnotatedString.Builder.appendCustomContent(
        richTextState: RichTextState
    ): AnnotatedString.Builder = this


    companion object {
        internal val DefaultSpanStyle = SpanStyle()

        val Default  = object  : RichSpanStyle {
                override val acceptNewTextInTheEdges: Boolean = true
            }
    }
}
